package com.njbdqn.myshops.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Date;

@CrossOrigin
@RestController
public class CustomActCtrl {
    @RequestMapping("/customAct")
    public void customAct(String act){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // F:\IT\study\bigdata\myact\logs/log_
        File file = new File("logs/log_" + sdf.format(new Date()) + ".log");
        try {
            RandomAccessFile raf = new RandomAccessFile(file, "rw");
            raf.seek(file.length());
            raf.writeBytes(act+"\r\n");
            raf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
